/**
 * 管理员主页需要的js
 */

/***********登出***********/
$("#logout").click(function () {
    $.ajax({
        type: "POST",
        url: "/manager/logout.do",
        success: function (value) {
            window.location.href = "/managerLogin.html"
        }
    });
});

layui.use('element', function () {
    var element = layui.element;
});
/*************修改密码****************/
layui.use(['layer'], function () {
    layer = layui.layer;
    $("#resetPass").click(function () {
        layer.open({
            title: '修改密码',
            skin: 'layui-layer-molv',
            anim: 2,
            shade: '#000',
            id: 'B_reset',
            shadeClose: true,
            btn: '确认提交',
            btnAlign: 'c', //按钮居中
            shade: 0.5,
            area: ['50%', '50%'],
            content: '<div class="layui-form-item">\n' +
                '    <label class="layui-form-label">新密码</label>\n' +
                '    <div class="layui-input-block">\n' +
                '        <input type="text" id="password" name="password" lay-verify="password"\n' +
                '               autocomplete="off" class="layui-input">\n' +
                '    </div>\n' +
                '</div>\n' +
                '<div class="layui-form-item">\n' +
                '    <label class="layui-form-label">确认密码</label>\n' +
                '    <div class="layui-input-block">\n' +
                '        <input type="text" id="Rpassword" name="Rpassword" lay-verify="password"\n' +
                '               autocomplete="off" class="layui-input">\n' +
                '    </div>\n' +
                '</div>' +
                '<center><i id="1" class="layui-bg-green layui-hide">两次密码输入不一致</i></center>',
            yes: function () {
                var password = $("#password").val();
                var Rpassword = $("#Rpassword").val();
                if (password != Rpassword) {
                    $("#1").removeClass("layui-hide");
                } else {
                    $.ajax({
                        type: 'POST',
                        url: '/manager/confirmPass.do',
                        data: {
                            password: password
                        },
                        success: function (value) {
                            if(value=="success"){
                                layer.msg("更新成功", {
                                    icon: 1,
                                    time: 500
                                }, function () {
                                   location.reload();
                                });
                            }else{
                                layer.msg("服务器好像出错了，请稍后重试", {
                                    icon: 2,
                                    time: 500
                                }, function () {
                                    location.reload();
                                });
                            }

                        }
                    });
                }

            }
        });
    });
});